<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>添加实验室</title>
    <link href="../css/register.css" rel="stylesheet">
    <script src="../js/jquery.js"></script>
</head>

<body>
<div class="container">
    <div class="card o-hidden border-0 shadow-lg my-5">
        <div class="card-body p-0">
            <!-- Nested Row within Card Body -->
            <div class="row">
                <div class="col-lg-7">
                    <div class="p-5">
                        <div class="user">
                            <!--                            <div class="form-group">-->
                            <!--                                <span style="color: red;font-size: 12px;">*</span>-->
                            <!--                                实验室ID:-->
                            <!--                                <label for="labid"></label>-->
                            <!--                                <input type="text" class="form-control form-control-user" id="labid">-->
                            <!--                            </div>-->
                            <div class="form-group">
                                <span style="color: red;font-size: 12px;">*</span>
                                实验室名称:
                                <label for="labname"></label>
                                <input type="text" class="form-control form-control-user" id="labname"
                                       name="labname">
                            </div>
                            <div class="form-group">
                                <span style="color: red;font-size: 12px;">*</span>
                                实验室地址:
                                <label for="address"></label>
                                <input type="text" class="form-control form-control-user" id="address">
                            </div>
                            <div class="form-group">
                                <span style="color: red;font-size: 12px;">*</span>
                                可容纳人数:
                                <label>
                                    <input type="number" class="form-control form-control-user" id="seats" value="0">
                                </label>
                            </div>
                            <div class="form-group">
                                <span style="color: red;font-size: 12px;">*</span>
                                详情:
                                <label for="remark"></label>
                                <textarea id="remark"></textarea>
                            </div>
                            <div class="form-group">
                                <span style="color: red;font-size: 12px;">*</span>
                                所属院系:
                                <label for="faculty"></label>
                                <select id="faculty">
                                    <option id="faculty1" selected>计算机科学与技术</option>
                                    <option id="faculty2">经济学院</option>
                                    <option id="faculty3">物理学院</option>
                                    <option id="faculty4">土木工程</option>
                                </select>
                            </div>
                            <div class="form-group">
                                <span style="color: red;font-size: 12px;">*</span>
                                类型:
                                <label for="role"></label>
                                <select id="role">
                                    <option id="role1" value="0" selected>公用实验室</option>
                                    <option id="role2" value="1">专用实验室</option>
                                </select>
                            </div>

                            <button type="button" class="btn btn-primary btn-user btn-block"
                                    onclick="addLab()">添加
                            </button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    $(function () {
        $.ajax({
            type: "post",
            url: "http://localhost:8080/user/getCurrentUser",
            success: function (result) {
                if (result.code != '200') {
                    alert("请先登录账号！");
                    window.location.href = "../../templates/login.html";
                }
            }
        });
    });

    function addLab() {
        let labid = $("#labid").val();
        let labname = $("#labname").val();
        let address = $("#address").val();
        let seats = $("#seats").val();
        let remark = $("#remark").val();
        let faculty = $("#faculty option:selected").text();
        let role = $("#role option:selected").val();

        let data = {
            "labid": labid,
            "labname": labname,
            "address": address,
            "seats": seats,
            "remark": remark,
            "faculty": faculty,
            "role": role
        };
        $.post('http://localhost:8080/lab/insertLab', data, function (result) {
            if (result.code == '200') {
                alert(result.msg);
                location.replace(location.href);
            } else {
                alert(result.msg);
            }
        });
    }
</script>
</body>
</html>